<template>
	<div>
		<div>
		   <div>
		        <el-button type="primary" @click="addBtn" size="mini">添加</el-button>
		    </div>
		</div>
		<br>
		<el-table  :data="list"
			 border  
			 style="width: 100%"
			>
			<el-table-column   align="center"    prop="cate"    label="分类"></el-table-column>
			<el-table-column  label="logo"   align="center">
			      <template slot-scope="scope">
			         <div>
						<img :src="scope.row.logo" style="width: 50px;height: 50px;border-radius: 50%;"></img>
			 		</div>
			      </template>
			  </el-table-column>
			  <el-table-column  label="二维码"   align="center">
			        <template slot-scope="scope">
			           <div>
							<el-image style="width: 50px; height: 50px"
							:preview-src-list="[scope.row.qr_code]"
							:src="scope.row.qr_code"></el-image>
			   		</div>
			        </template>
			    </el-table-column>
				<el-table-column  label="内容"   align="center">
				     <template slot-scope="scope">
				        <div v-html="scope.row.content" />
				     </template>
				 </el-table-column>
			 <!-- <el-table-column  label="状态"   align="center">
			      <template slot-scope="scope">
			         <div>
						<el-tag v-if="scope.row.status==0" size="small" effect="dark" type="danger">禁用</el-tag>
						<el-tag v-if="scope.row.status==1" size="small" effect="dark">启用</el-tag>
			 		</div>
			      </template>
			  </el-table-column> -->
			<el-table-column   align="center"    prop="add_time"    label="添加时间"></el-table-column>
			<el-table-column   align="center"    prop="update_time"    label="修改时间"></el-table-column>
			
		   <el-table-column  label="操作"   align="center">
		        <template slot-scope="scope">
		            <el-button type="text" @click="editRow(scope.row)">编辑</el-button>
					<el-button type="text" @click="delRow(scope.row.id)">删除</el-button>
		        </template>
		    </el-table-column>
		</el-table>
		<div class="page">
		    <el-pagination
		            background
		            @size-change="pageChange"
		            @current-change="handleCurrentChange"
		            :current-page="page"
		            :page-size="pageSize"
		            layout="total, sizes, prev, pager, next, jumper"
		            :total="page_totle">
		    </el-pagination>
		</div>
		<el-dialog
		        :title="addTitle"
				:close-on-click-modal="false"
		        :visible.sync="formShow"
		        width="1000px"
		>
		  <div>
			  <el-form ref="form" :model="form" label-width="80px">
				  <el-form-item label="分类">
				      <el-select v-model="form.cate_id" 
						style="width: 300px;"
						size="small" placeholder="请选择">
				          <el-option
				            v-for="item in cateList"
				            :key="item.id"
				            :label="item.cate"
				            :value="item.id">
				          </el-option>
				        </el-select>
				  </el-form-item>
				  <el-form-item label="状态">
				      <el-radio-group v-model="form.status">
				        <el-radio label="0">禁用</el-radio>
				        <el-radio label="1">启用</el-radio>
				      </el-radio-group>
				    </el-form-item>
				  <el-form-item label="内容">
				     <!-- <el-input type="textarea" 
						 :rows="10"
						v-model="form.content" size="small"></el-input> -->
					  <edit />
				  </el-form-item>
				  <el-form-item >
				      <el-button type="primary" @click="confirm" size="small">确定</el-button>
				  </el-form-item>
			  </el-form>
		  </div>
		</el-dialog>
	</div>
</template>

<script>
	import edit from '@/components/wangEditor'
	export default {
		data(){
			return {
				title:"",
				page:1,
				pageSize:10,
				form:{
					id:null,
					content:"",
					cate_id:'', //分类id
					status:'1'
				},
				addTitle:'新增',
				cateList:[]
			}
		},
		components:{
			edit
		},
		mounted() {
			this.lodeCateList()
			this.lodeList()
		},
		methods:{
			lodeCateList(){
				let params = {
					title:'',
				}
				this.$post('/homeSet/getNewMessageCate',params,res=>{
					let data = res.data.data
					this.cateList = data.result
				})
			},
			editRow(row){
				this.addTitle = '编辑'
				for(let i in this.form){
					this.form[i] = row[i]
				}
				setTimeout(()=>{
					window.$editor.txt.html(row.content)
				},100)
				this.formShow = true
			},
			delRow(id){
				this.$confirm('确定删除', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
				          this.$post('/homeSet/delNewMessage',{ids:[id]},res=>{
							  this.lodeList()
						  })
				        })
			},
			clearSearch(){
				this.title = ''
				this.search()
			},
			confirm(){
				this.form.content = window.$editor.txt.html()
				this.$post('/homeSet/addEditNewMessage',this.form,res=>{
					if(res.data.code==200){
						this.$message.success('操作成功')
						this.formShow = false
						this.lodeList()
					}
				})
			},
			addBtn(){
				this.addTitle = '新增'
				this.form={
					id:null,
					content:"",
					cate_id:'', //分类id
					status:'1'
				}
				setTimeout(()=>{
					window.$editor.txt.html('')
				},100)
				this.formShow = true
			},
			lodeList(){
				let params = {
					title:this.title,
					page:this.page,
					pageSize:this.pageSize,
					status:''
				}
				this.$post('/homeSet/getNewMessage',params,res=>{
					let data = res.data.data
					this.page_totle = data.count
					this.list = data.result
				})
			},
		}
	}
</script>

<style>
</style>